<template>
	<view class="order-wrapper">
		<view class="order-tab">
			<u-tabs :list="list" :scrollable="false" :current="current" lineColor="#CF1A1B" lineWidth="55"
				lineHeight="4" :activeStyle="{
	  			color: '#CF1A1B',
				'font-size':'14px'
	  		}" :inactiveStyle="{
	  			color: 'rgba(0,0,0,0.65)',
				'font-size':'14px'
	  		}" itemStyle="height: 44px;" @change="handleTab">
			</u-tabs>
		</view>
		<view v-if="orderList.length == 0" class="empty">
			<image src="@/static/empty.png"></image>
			<text>无数据</text>
		</view>
		<view class="list-wrapper">
			<view class="order-list" v-for="item in orderList">
				<view class="order-item">
					<view class="order-item-h">
						<view class="store-name">
							<image class="img" src="../../static/img/tabbar/ic_store.png"></image>
							<text class="name">{{ item.terminalName }}</text>
						</view>
						<view class="order-status">
							<text  style="color:#F68B53">待评价</text>
						</view>
					</view>
					<view class="order-item-c">
						<view class="goods-list">
							<view class="goods-item" v-for="(list,index) in item.orderItems">
								<view class="goods-img">
									<image class="img"
										:src="list.image?list.image:'https://coach-vehicle-uat-1313990257.cos.ap-beijing.myqcloud.com/miniapp/order/goods_default_square.png'">
									</image>
								</view>
								<view class="goods-info"
									:class="{'end-goods-info':index == (item.orderItems.length - 1) }">
									<view class="info">
										<view class="goods-name">{{ list.goodsName }}</view>
										<!-- <view class="goods-pid">{{ list.propertiesDesc }}</view> -->
										<view class="goods-price">
											<view class="price"> <text
													style="font-size: 12px;">￥</text>{{ list.sellPrice.toFixed(2) }}
											</view>
											<view class="num">×{{ list.quantity }}</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="goods-total">共 {{ item.orderItems.length }} 件商品 应付金额：
						<text class="total-price">
							<text style="font-size: 12px;">￥</text>{{ item.actuallyPrice.toFixed(2)}}
						</text>
					</view>
					<view class="order-item-b">
						<u-button type="primary" text="去评价" size="small"
							@click.native.stop="onRate(item)"></u-button>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="status" v-if="loadVisible" :contentText="contentText" />
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {
				current: 0,
				list: [{
						name: '待评价',
						status: 6
					}, {
						name: '已评价',
						status: 1,
					}
				],
				orderState: 6,
				pageNum: 1,
				pageSize: 10,
				orderList: [],
				total: 0,
				emptyVisible: false,
				status: 'more',
				loadVisible: false,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了",
				},
				orderStates: null
			}
		},
		computed: {
			...mapGetters('user', ['getUserInfo']),
		},
		methods: {
			handleTab(e) {
				this.orderState = e.status
				this.pageNum = 1
				this.orderList = []
				this.current = e.index
				this.orderStates = null
				this.initData()
			},
			//获取数据
			async initData() {
				try {
					const res = await this.$request({
						method: 'POST',
						url: '/order-center/car-owner-order/getOrderByUserId',
						data: {
							loginUserId: this.getUserInfo.id,
							orderState: this.orderState,
							pageNum: this.pageNum,
							pageSize: this.pageSize,
							orderStates: this.orderStates
						}
					})
					this.orderList = this.orderList.concat(res.data)
					this.total = res.count
					this.loadVisible = this.total > this.pageSize
					this.emptyVisible = this.total === 0
					uni.hideLoading()
				} catch (res) {
					uni.hideLoading()
					uni.showToast({
						title: '请求失败',
						icon: 'error'
					})
				}

				uni.stopPullDownRefresh();
			},
			//去评价
			onRate(item) {
				// uni.navigateTo({
				// 	url: '/orderPack/detail/index',
				// 	success: (res) => {
				// 		res.eventChannel.emit('detailInfo', {
				// 			data: item
				// 		})
				// 	}
				// })
			},
		},

		onReachBottom() {
			if (this.orderList.length >= this.total) {
				this.status = 'noMore'
				return
			}
			this.loadVisible = true
			this.status = 'loading'
			this.pageNum++
			this.initData()
		},
		onPullDownRefresh() {
			this.loadVisible = false
			this.pageNum = 1
			this.initData()
		},
		onLoad() {
			uni.showLoading({
				title: '加载中...'
			})
			this.initData()
		}

	}
</script>

<style lang="scss" scoped>
	.order-wrapper {
		width: 100%;
		height: 100%;
		font-size: 14px;
		box-sizing: border-box;
		padding-bottom: env(safe-area-inset-bottom);

		/deep/ .u-tabs__wrapper__nav__line {
			margin-left: 16px;
		}

		/deep/ .u-tabs__wrapper__nav__item {
			padding: 0;
		}

		.empty {
			width: 100%;
			height: 80%;
			position: absolute;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			image {
				width: 220px;
				height: 180px;
			}

			text {
				font-size: 30rpx;
				color: rgba(0, 0, 0, 0.45);
				line-height: 30rpx;
			}
		}

		.order-tab {
			z-index: 99;
			position: fixed;
			width: 100%;
			top: 0;
			background-color: #FFFFFF;
		}

		.list-wrapper {
			padding-top: 108rpx;
		}

		.order-list {
			.order-item {
				background: #fff;
				margin-bottom: 20rpx;

				.order-item-h {
					padding: 28rpx 32rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					align-content: center;
					border-bottom: 2rpx solid rgba(0, 0, 0, 0.1);

					.store-name {
						display: flex;
						flex: 1;
						color: rgba(0, 0, 0, 0.85);
						width: calc(100% - 200rpx);

						.img {
							width: 36rpx;
							height: 36rpx;
							margin-right: 10rpx;
						}

						.name {
							flex: 1;
							max-width: calc(100% - 46rpx);
							word-wrap: break-all;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 1;
							text-shadow: 0 0 0.1px currentcolor;
							line-clamp: 1;
							-webkit-box-orient: vertical;
						}
					}

					.order-status {
						width: 200rpx;
						text-align: right;
					}
				}

				.order-item-c {
					padding: 16rpx 26rpx;

					.goods-list {
						border-bottom: 2rpx solid rgba(0, 0, 0, 0.1);
					}

					.goods-item {
						display: flex;
						justify-content: flex-start;
						align-items: center;
						padding: 20rpx 0;

						.goods-img {
							height: 176rpx;
							width: 176rpx;
							margin-right: 24rpx;

							.img {
								width: 100%;
								height: 100%;
							}
						}

						.goods-info {
							flex: 1;
							display: flex;
							height: 180rpx;
							justify-content: flex-start;
							align-items: center;
							width: calc(100% - 200rpx);
							border-bottom: 2rpx solid rgba(0, 0, 0, 0.1);

							.info {
								width: 100%;
							}

							.goods-name {
								font-size: 15px;
								font-weight: 500;
								color: rgba(0, 0, 0, 0.85);
								margin-bottom: 14rpx;
								word-wrap: break-all;
								overflow: hidden;
								text-overflow: ellipsis;
								display: -webkit-box;
								-webkit-line-clamp: 2;
								line-clamp: 2;
								-webkit-box-orient: vertical;

							}

							.goods-pid {
								margin-bottom: 22rpx;
								color: rgba(0, 0, 0, 0.65);
							}

							.goods-price {
								display: flex;
								width: 100%;
								justify-content: space-between;
								align-items: center;
								margin-top: 48rpx;

								.price {
									font-size: 18px;
									color: #EE3B3B;
									font-weight: bold;
								}

								.num {
									font-size: 14px;
									font-weight: 500;
									color: rgba(0, 0, 0, 0.85);
								}
							}
						}

						.end-goods-info {
							border-bottom: none;
						}
					}
				}

				.goods-total {
					display: flex;
					justify-content: flex-end;
					font-size: 14px;
					color: rgba(0, 0, 0, 0.65);
					padding: 32rpx 26rpx;
					padding-top: 20rpx;

					.total-price {
						color: #F83E48;
						font-weight: 400;
					}
				}

				.order-item-b {
					height: auto;
					overflow: hidden;
					padding-bottom: 20rpx;

					/deep/ .u-button {
						width: auto;
						margin-right: 20rpx;
						float: right;
					}
				}
			}
		}
	}
</style>

